﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using Core.Dao;
using System.Data;

namespace Core.Business
{
    public class TicketCategoryBus
    {
        private TicketCategoryDao dao;
        public TicketCategoryBus() {
            dao = new TicketCategoryDao();
        }

        public bool insert(TicketCategory ticketCategory) {
            return dao.insert(ticketCategory);
        }

        public bool update(TicketCategory ticketCategory) {
            return dao.update(ticketCategory);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public TicketCategory get(int id) {
            DataTable dt = dao.get(id);
            TicketCategory ticketCategory = new TicketCategory();

            if (dt.Rows.Count > 0)
            {
                ticketCategory.Id = Convert.ToInt32(dt.Rows[0]["TKC_ID"]);
                ticketCategory.Name = dt.Rows[0]["TKC_NAME"].ToString();
                ticketCategory.Desc = dt.Rows[0]["TKC_DESC"].ToString();
            }
            return ticketCategory;
        }

        public List<TicketCategory> getAll() {
            DataTable dt = dao.getAll();
            List<TicketCategory> list = new List<TicketCategory>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    TicketCategory ticketCategory = new TicketCategory();
                    ticketCategory.Id = Convert.ToInt32(dr["TKC_ID"]);
                    ticketCategory.Name = dr["TKC_NAME"].ToString();
                    ticketCategory.Desc = dr["TKC_DESC"].ToString();

                    list.Add(ticketCategory);
                }

            }
            return list;
        }

        public List<TicketCategory> getAllByServiceTypeIdAndDepartmentId(int serviceTypeId, int departmentId)
        {
            DataTable dt = dao.getAllByServiceTypeIdAndDepartmentId(serviceTypeId, departmentId);
            List<TicketCategory> list = new List<TicketCategory>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    TicketCategory ticketCategory = new TicketCategory();
                    ticketCategory.Id = Convert.ToInt32(dr["TKC_ID"]);
                    ticketCategory.Name = dr["TKC_NAME"].ToString();
                    ticketCategory.Desc = dr["TKC_DESC"].ToString();

                    list.Add(ticketCategory);
                }

            }
            return list;
        }
    }
}
